#include <stdio.h>
#include <string.h>

char list1[52][52];
char list2[52][52];
int n, m;

bool init()
{
    if (scanf("%d %d", &n, &m)==EOF) return false;
    int i;
    for (i=0; i<n; ++i)
        scanf("%s %s", list1[i], list2[i]);    
    return true;
}    
char ss[50];
int getPos()
{
    int i;
    for (i=0; i<n; ++i)
        if (strcmp(list1[i], ss)==0)
            return i;
    return -1;
}    


void deal()
{
    int len, pos;    
    while (m--)
    {
        memset(ss, 0, sizeof(ss));
        scanf("%s", ss);
        len = strlen(ss);
        if ((pos=getPos()) != -1)
        {
            printf("%s\n", list2[pos]);
        }    
        else if (len >1 && ss[len-1] == 'y' && 
                 ss[len-2]!='a' &&  ss[len-2]!='e' &&  ss[len-2]!='i' &&  ss[len-2]!='o' && 
                  ss[len-2]!='u'
                 )
        {
         
            strcpy(&ss[len-1], "ies");
            printf("%s\n", ss);
        }    
        else if ( ss[len-1] == 'o' ||
                  ss[len-1] == 's' ||
                  ss[len-1] == 'x' ||        
                  ( len > 1 && ss[len-2]=='c' && ss[len-1] == 'h' ) ||
                  ( len > 1 && ss[len-2]=='s' && ss[len-1] == 'h' ))
       {
           printf("%ses\n", ss);
       }    
       else 
       {
           printf("%ss\n", ss);
       }    
        
    }    
}    

int main()
{
    while (init())
    {
        deal();
    }    
    return 0;
}    

